module.exports = (success, error) => {
    const mongoose = require('mongoose')

    if(typeof error !='function'){
        error = ()=>{
            console.log('数据库连接出错')
        }
    }

    mongoose.connect('mongodb://127.0.0.1/todo')

    mongoose.connection.once('open',()=>{
        success()
    })

    mongoose.connection.on('error', ()=>{
        error()
    })

    mongoose.connection.on('close',()=>{
        console.log('关闭数据库连接')
    })
}